package com.suzhouhe.util.config.date;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.suzhouhe.util.utils.DateUtil;

import java.io.IOException;
import java.time.LocalDateTime;

/**
 * 时间序列化处理 将localDateTime类型的时间转换为Long类型的时间戳
 *
 * @author suzhouhe
 * @date 2020-08-18 11:58
 **/
public class ResponseLocalDateTimeToLongSerializer extends JsonSerializer<LocalDateTime> {

    @Override
    public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException {
        gen.writeNumber(DateUtil.localDateTimeToLong(value));
    }
}
